package com.gin.kotlin.gf2gamecommunity.base.composable

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

@Composable
fun ConfirmDialog(
    modifier: Modifier = Modifier,
    onDismissRequest: () -> Unit,
    onConfirmation: () -> Unit,
    thirdButtonText: String = "",
    thirdButtonOnclick: () -> Unit = {},
    content: @Composable () -> Unit
) {
    Dialog(onDismissRequest = onDismissRequest) {
        Card(
            shape = RoundedCornerShape(16.dp),
        ) {
            Column(
                modifier = modifier.padding(16.dp),
            ) {
                content()

                Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
                    Row {
                        if (thirdButtonText.isNotEmpty()) TextButton(
                            onClick = { thirdButtonOnclick() },
                            modifier = Modifier.padding(2.dp),
                        ) {
                            Text(thirdButtonText)
                        }
                    }

                    Row {
                        TextButton(
                            onClick = { onDismissRequest() },
                            modifier = Modifier.padding(2.dp),
                        ) {
                            Text("取消")
                        }
                        TextButton(
                            onClick = { onConfirmation() },
                            modifier = Modifier.padding(2.dp),
                        ) {
                            Text("确认")
                        }
                    }
                }
            }
        }
    }
}